import globalModal from '../components/globalModal.vue';

let modalConstructor = Vue.extend(globalModal);

const modal = new modalConstructor({
    el: document.createElement('div'),
    data() {
        return {
            tipInfo: {
                tipTitle: '温馨提示',
                msg: '',
                tipBtn: ['确定']
            },
            close: false,
        }
    }
}).$mount();

const showModal = options => {
    modal.$data.tipInfo.tipTitle = options.tipTitle ? options.tipTitle : '温馨提示';
    modal.$data.tipInfo.msg = options.msg ? options.msg : '未能处理您的请求！';
    modal.$data.tipInfo.tipBtn = options.tipBtn ? options.tipBtn : ['确定'];
    modal.$data.close = options.close;
    modal.handler = options.handler ? options.handler : () => { };
    document.body.appendChild(modal.$el);
}

const hideModal = function() {
    document.body.removeChild(modal.$el);
}

Vue.prototype.$showModal = showModal;
Vue.prototype.$hideModal = hideModal;

// export { showModal,hideModal}